package cn.tedu.ivos.dict.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.dto.DictSaveParam;
import cn.tedu.ivos.dict.pojo.vo.DictVO;
import cn.tedu.ivos.dict.service.DictService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1/dict")
@Tag(name = "字典模块")
@Slf4j
@Validated
public class DictController {
    @Autowired
    private DictService dictService;


    @Operation(summary = "查询字典")
    @ApiOperationSupport(order = 10)
    @GetMapping("/select")
    public JsonResult selectDict(@Validated DictQuery dictQuery){
        log.debug("查询字典:DictQuery={}", dictQuery);
        List<DictVO> listDictVO = dictService.selectDict(dictQuery);
        return JsonResult.ok(listDictVO);
    }

    @Operation(summary = "新增字典")
    @ApiOperationSupport(order = 20)
    @PostMapping("/save")
    public JsonResult insertDict(@Validated DictSaveParam dictSaveParamParam){
        log.debug("新增字典:DictSaveParam={}", dictSaveParamParam);
        dictService.insertDict(dictSaveParamParam);
        return JsonResult.ok();
    }
}
